<?php
namespace app\admin\controller;

use app\common\controller\Back;

class Apis extends Back
{
    protected function initialize()
    {
        parent::initialize();
    }
    
    public function index()
    {
        $form = dcFormCreate([
            'name'         => 'adminApisIndex',
            'action'       => dcUrl('admin/apis/update'),
            'items'        => $this->formItems(config('apis.')),
            'reset'        => '重置',
            'class_button' => 'text-left',
        ]);

        $this->assign('form',$form);

        $this->assign($this->site);

        return $this->fetch();
    }

    public function update()
    {
        $post = dcArrayFilter(input('post.'), array_keys($this->formItems()));

        $post = array_merge(config('apis.'),$post);

        $this->configSave('./config/apis.php', $post, 'admin/apis/index');
    }
    
    private function formItems($data=[])
    {
        return [
            'daicuo_token' => [
                'type'        => 'text',
                'value'       => $data['daicuo_token'],
                'required'    => false,
                'title'       => '阿呆APITOKEN',
                'placeholder' => '解析抖音接口时使用此认证参数',
                'class_row'   => 'border-bottom mb-3 pb-3',
                'class_label' => 'form-label',
            ],
            'aliyun_key' => [
                'type'        => 'text',
                'value'       => $data['aliyun_key'],
                'required'    => false,
                'title'       => '阿里云APIKEY',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'aliyun_secret' => [
                'type'        => 'text',
                'value'       => $data['aliyun_secret'],
                'required'    => false,
                'title'       => '阿里云API密钥',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
        ];
    }
}